package com.cs.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cs.entity.Result;
import com.cs.pojo.Course;
import com.cs.service.CourseService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Reference
    private CourseService courseService;

    /***
     * @description 获得所有的课程
     *
     * @param
     * @date 2019/6/20 22:02
     * @return java.util.List<com.cs.pojo.Course>
     */
    @RequestMapping("/getCourse.do")
    public List<Course> getCourse() {
        return courseService.getCourse();
    }

    /***
     * @description 新增课程
     *
     * @param course
     * @date 2019/6/20 22:04
     * @return com.cs.entity.Result
     */
    @RequestMapping("/addCourse.do")
    public Result addCourse(@RequestBody Course course) {
        Result result = null;
        try {
            result = courseService.addCourse(course);
        } catch (Exception e) {
            result = new Result(false, e.getMessage());
        }
        return result;
    }


    /***
     * @description 删除课程
     *
     * @param id
     * @date 2019/6/20 22:04
     * @return com.cs.entity.Result
     */
    @RequestMapping("/deleteCourse.do")
    public Result deleteCourse(Integer[] id) {
        Result result = null;
        try {
            result = courseService.deleteCourse(id);
        } catch (Exception e) {
            result = new Result(false, e.getMessage());
        }
        return result;
    }


    /***
     * @description 修改课程
     *
     * @param course
     * @date 2019/6/20 22:05
     * @return com.cs.entity.Result
     */
    @RequestMapping("/updateCourse.do")
    public Result updateCourse(@RequestBody Course course) {
        Result result = null;
        try {
            result = courseService.updateCourse(course);
        } catch (Exception e) {
            result = new Result(false, e.getMessage());
        }
        return result;
    }

    /***
     * @description 根据id查找课程
     *
     * @param id
     * @date 2019/6/20 22:05
     */
    @RequestMapping("/findCourseById.do")
    public Course findCourseById(Integer id) {
        return courseService.findCourseById(id);
    }

    /**
     *   按名称模糊查找课程
     * @param course
     * @return
     */
    @RequestMapping("/findCourseFuzzy.do")
    public List<Course> findCourseFuzzy(@RequestBody Course course) {
        List<Course> courses = null;
        try {
            courses = courseService.findCourseFuzzy(course);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return courses;
    }


}
